Skip to content

Conversation

amunger
Copy link
Contributor

@amunger amunger commented Oct 6, 2025

fix microsoft/vscode#268430

the language service works with text document URIs, which cells have, but not Notebook URIs.
This change collects diagnostics for all cells within the requested notebook.

@amunger amunger requested a review from roblourens October 6, 2025 22:08
@amunger amunger marked this pull request as ready for review October 6, 2025 22:08
@Copilot Copilot AI review requested due to automatic review settings October 6, 2025 22:08
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for retrieving diagnostics/errors from Jupyter notebook URIs by implementing special handling for notebook cells. When a notebook URI is detected, the tool now iterates through all cells in the notebook and collects diagnostics from each cell's document rather than trying to get diagnostics from the notebook URI directly.

Key changes:

  • Added notebook URI detection and specialized diagnostic collection for notebook cells
  • Reorganized imports and moved diagnostic filtering logic for better code structure
  • Added error logging when notebook documents cannot be found


private getNotebookCellDiagnostics(uri: URI) {
const notebook = this.workspaceService.notebookDocuments
.find((doc: { uri: URI }) => doc.uri.toString() === uri.toString());
Copy link
Preview

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The URI comparison using toString() is inefficient and may not handle URI normalization correctly. Consider using URI's built-in comparison methods like uri.toString() === doc.uri.toString() with proper URI normalization, or use VS Code's URI comparison utilities if available.

Suggested change
.find((doc: { uri: URI }) => doc.uri.toString() === uri.toString());
.find((doc: { uri: URI }) => URI.equals(doc.uri, uri));

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not a real function

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the better approach is to use isEqual function found in resources.ts

Copy link
Collaborator

@DonJayamanne DonJayamanne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change should apply to all notebooks, not just Jupyter.
Includes few non critical suggestions.


diagnostics = diagnostics.filter(d => d.severity <= DiagnosticSeverity.Warning);
let diagnostics: vscode.Diagnostic[] = [];
if (isJupyterNotebookUri(uri)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be used for all notebooks, not just Jupyter?
I think you can use INotebookService.hasSupportedNotebook to check if Uri is a notebook document


private getNotebookCellDiagnostics(uri: URI) {
const notebook = this.workspaceService.notebookDocuments
.find((doc: { uri: URI }) => doc.uri.toString() === uri.toString());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the better approach is to use isEqual function found in resources.ts

}

private getNotebookCellDiagnostics(uri: URI) {
const notebook = this.workspaceService.notebookDocuments
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest using findNotebook function from notebooks.ts (that does what you're doing here and you also don't need to do the uri.toString)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_errors tool/API doesn't capture Pylance type checking errors in Jupyter notebooks
2 participants